<template>
	<view class="">
		<view class="content">
			<!-- 头部banner -->
			<detail-swiper :list="swiperList"></detail-swiper>
			<view class="content_info">

				<!-- 活动具体信息 -->
				<detail-info :activityTitle="activityInfo.activityName"
					:activiyTime="activityInfo.timeStart+'至'+activityInfo.timeEnd" :finishTime="activityInfo.timeEnd">

					<view class="other-content" slot="other">
						<image class="seckillTitleBg" src="../static/activity/seckillBg.png" mode=""></image>
						
						<view class="seckillInfo">
							<text class="seckillTitle">秒杀价</text>
							<view class="nowPrice">¥
								<text style="font-size: 36upx;color: #ec4863;">{{activityInfo.nowPrice}}</text>
							</view>
							<text class="countNumber">仅剩{{activityInfo.countNumber - activityInfo.number}}份</text>
						</view>
						

						<view class="costPrice">¥{{activityInfo.costPrice}}</view>

					</view>
				</detail-info>

				<!-- 活动门店 -->
				<view v-if="activityInfo.unitDto">
					<home-title title="活动门店" type="2"></home-title>
					<view style="margin-bottom: 10upx;" v-for="(item, index) in activityInfo.unitDto" :key="index">
						<store-cell :isLocation="0" :storeName="item.applicableUnit" :storeAddress="item.unitAddress"
							:distance="item.distance" :phone="item.unitPhone" :latitude="item.unitLat"
							:longitude="item.unitLon"></store-cell>
					</view>
				</view>

				<!-- 活动商品 -->
				<view v-if="activityInfo.goodsVoList">
					<home-title title="商品说明" type="2"></home-title>
					<view v-for="(item, index) in activityInfo.goodsVoList" :key="index" class="goods">
						<detail-commodity :commodityTitle="item.goodsServerName"
							:commodityDesc="item.goodsServerDescribe" :count="item.goodsServerNumber"
							:totalAmount="item.goodsServerPrice" :totalPrice="'{{item.goodsServerNumber * item.goodsServerPrice}}'"></detail-commodity>
					</view>
				</view>

				<!-- 活动介绍 -->
				<detail-introduce :richInfo="activityInfo.content"></detail-introduce>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="bottomView">
			<view class="btn leftBtn">
				分享好友
				<button style="position: absolute; width: 100%; height: 100%; opacity: 0;" open-type="share"></button>
			</view>
			<view class="btn rightBtn" @click="confimOrder">
				立即抢购
			</view>
		</view>
	</view>
</template>

<script>
	import detailSwiper from "@/components/activity/activity-detailSwiper.vue"
	import detailInfo from '@/components/activity/activity-detailInfo.vue'
	import homeTitle from '@/components/layout/mmv-home-title.vue'
	import storeCell from '@/components/coupon/store-cell.vue'
	import detailCommodity from '@/components/activity/activity-detailCommodity.vue'
	import detailIntroduce from '@/components/activity/activity-detailIntroduce.vue'

	import {
		apiActivityInfo,
		insertActivityBrowseRecords
	} from '@/api/marketing-api.js'
	import GLOBAL_CONFIG from '@/settings.js';
	export default {
		components: {
			detailSwiper,
			detailInfo,
			homeTitle,
			storeCell,
			detailCommodity,
			detailIntroduce
		},
		data() {
			return {
				startTime: 0,
				endTime: 0,
				lat: 0,
				lon: 0,
				activityId: '',
				activityInfo: {},
				swiperList: [],
				baseImageUrl: GLOBAL_CONFIG.baseImageUrl,
			}
		},
		// onLoad(op) {
		// 	this.reckonBytime()
		// },
		computed: {
		  	memberNo() {
				return this.$store.state.user.userInfo.memberNo
			},
			duration() {
				return this.endTime - this.startTime;
			}
		},
		beforeDestroy() {
			this.insertActivityBrowseRecords()
		},
		methods: {
			insertActivityBrowseRecords() {
				//记录离开页面的时间
				this.endTime = new Date().getTime();
				insertActivityBrowseRecords({
					bizNo: this.activityId,
					memberNo: this.memberNo,
					browseDuration: this.duration,
					tenantId: this.$store.state.user.tenantId,
					activityType: 1
				}).then(res => {})
			},
			//获取定位信息
			getLocation() {
				uni.getLocation({
					type: 'wgs84',
					success: (res => {
						this.lat = res.latitude;
						this.lon = res.longitude;
						this.getData();
					})
				});
			},
			//获取详情数据
			getData() {
				let that = this;
				apiActivityInfo({
					bizNo: that.activityId,
					lon: this.lon,
					lat: this.lat
				}).then(res => {
					this.activityInfo = res.data;
					if (this.activityInfo.detailsImage.length > 0) {
						let arr = this.activityInfo.detailsImage.split(',');
						this.swiperList = arr.map(item => {
							return GLOBAL_CONFIG.baseImageUrl + item;
						})
					}
				})
			},

			onShareAppMessage(res) {
				return {
					title: this.activityInfo.activityName,
					imageUrl: this.baseImageUrl + this.activityInfo.shareImage,
					path: '/pagesB/activity/activityDetail-secondKill?bizNo=' + this.activityId +'&scene='+this.memberNo
				}
			},



			confimOrder() {
				if(!this.$store.state.user.isLogin){
					uni.navigateTo({
						url:'../../pages/login/login'
					})
					return
				}
				uni.navigateTo({
					url: './activity-confimOrder?bizNo=' + this.activityId
				})
			}
		},
		onLoad(op) {
			//记录进去页面的时间
			this.startTime = new Date().getTime();
			this.activityId = op.bizNo;
			if (op.scene) {
				let memberNo = op.scene; // memberNo
				if (memberNo) {
					// 存入分享上级
					this.$store.commit('user/saveinviterId', memberNo);
				}
			}
			this.getLocation();
		},
		onShareTimeline() {
			return {
				title: this.activityInfo.luckdrawName,
				imageUrl: this.baseImageUrl + this.activityInfo.shareImage,
				path: '/pagesB/activity/activityDetail-secondKill?bizNo=' + this.activityId + '&scene='+this.memberNo
			}
		}

	}
</script>

<style lang="scss" scoped>
	.content {
		margin-bottom: 100upx;

		&_info {
			padding: 0 30upx;
			position: relative;
			top: -60upx;
		}
	}

	.secondKill {
		margin: 10upx 0;
		position: relative;
	}

	.seckillInfo {
		// position: relative;
		display: flex;
		justify-content: space-around;
		align-items: center;
		// vertical-align: bottom;
	}

	.seckillTitle {
		color: #fff;
		font-size: 22upx;
		z-index: 100;
		margin-left: 8upx;
	}

	.nowPrice {
		font-size: 22upx;
		font-family: PingFang SC, PingFang SC-Bold;
		font-weight: bold;
		font-style: italic;
		text-align: left;
		color: #ec4863;
		// margin-top: 23upx;
		margin-left: 15upx;
		margin-right: 23upx;
	}

	.countNumber {
		font-size: 24upx;
		font-family: PingFang SC, PingFang SC-Bold;
		// font-weight: bold;
		// text-align: left;
		color: #ec4863;
	}

	.costPrice {
		font-size: 28upx;
		font-family: PingFang SC, PingFang SC-Medium;
		// font-weight: bold;
		font-style: italic;
		// text-align: left;
		text-decoration: line-through;
		color: #999999;
		margin-top: 23upx;
	}
	
	.other-content{
		position: relative;
	}
	
	.seckillTitleBg {
		top: 6upx;
		left: 0;
		position: absolute;
		width: 86upx;
		height: 38upx;
	}

	.bottomView {
		display: flex;
		width: 100%;
		height: 96upx;
		line-height: 96upx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 3;
	}

	.btn {
		width: 50%;
		line-height: 100%;
		font-size: 33upx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
	}

	.leftBtn {
		color: #666;
		background-color: #FFFFFF;
		height: 96upx;
		line-height: 96upx;
		align-self: center;
		text-align: center;
	}

	.rightBtn {
		color: #fff;
		background-color: $main-color;
	}
	
	.goods{
		padding-top: -20upx;
	}
</style>
